/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.kpi.transport.servlet.actions.lists;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ua.kpi.transport.db.dao.factory.DAOFactory;
import ua.kpi.transport.db.dao.factory.DBEnum;
import ua.kpi.transport.db.dao.interfaces.IRouteDAO;
import ua.kpi.transport.db.entities.FullRouteBean;
import ua.kpi.transport.db.entities.RouteBean;
import ua.kpi.transport.servlet.actions.IAction;
import ua.kpi.transport.util.settings.Pages;

/**
 *
 * @author harker777
 */
public class RoutesListAction implements IAction{

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        IRouteDAO rd = DAOFactory.getDAOFactory(DBEnum.MYSQL).getRouteDAO();
        List<FullRouteBean> routes = new ArrayList<FullRouteBean>();
        
        for (RouteBean route : rd.findAll()) {
            routes.add(rd.findFull(route));
        }
        
        request.setAttribute("routes", routes);

        String page = Pages.getPage(Pages.ROUTES_PAGE);
        return page;
    }
    
}
